﻿using Inovout.Kuajing.Exports.Models;
using Inovout.Kuajing.Exports.Services;
using Inovout.Organizations.Memberships.Models;
using Inovout.Services;
using Inovout.Web.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Inovout.Kuajing.Exports.Console.Web.Controllers
{

    public class DrawerController : KJBaseController<Drawer>
    {
        
        private IExporterService exporterService;
        private IDrawerService drawerService;
        public DrawerController(IExporterService exporterService, IDrawerService drawerService) 
        {
            this.exporterService = exporterService;
            this.drawerService = drawerService;
        }
        [HttpPost]
        public JsonResult FilterDrawer(string term, string Id)
        {
            //Exporter exporter = null;
            //if (Id != "0")
            //{
            //    string exporterId = Id;
            //    exporter = exporterService.FindById(int.Parse(exporterId));
            //}

            //IRepositoryService<OrganizationMembership> organizationMembershipService = ComponentRegistry.Resolve<IRepositoryService<OrganizationMembership>>();
            //OrganizationMembership organizationMembership = organizationMembershipService.FindById(exporter.Membership.Id);

            //List<Drawer> drawerList = (List<Drawer>)drawerService.FindByKey(term, organizationMembership.Organization);
            List<Drawer> drawerList = (List<Drawer>)drawerService.FindAll();
            var data = from c in drawerList
                       select new { value = c.Id, label = c.Name};
            return Json(data, JsonRequestBehavior.AllowGet);
        }
	}
}